package com.jbpm.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * 登陆
 * @author 周文滔 <zhouwentao16@gmail.com>
 * @time 2012-5-27 下午05:39:53
 */
public class LoginServlet extends HttpServlet {
	private String username = "";

	public LoginServlet() {
		super();
	}

	public void init() throws ServletException {
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		setUsername(new String(request.getParameter("username").getBytes(
				"ISO-8859-1"), "UTF-8"));
		HttpSession session = request.getSession();
		System.out.println(getUsername());
		if (username.equals("陈老师")) {
			session.setAttribute("rule", 1);
		} else {
			session.setAttribute("rule", 0);
		}
		session.setAttribute("username", username);
		request.getRequestDispatcher("leave?action=list").forward(request,
				response);

	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}

}
